/**
*Manually added by Hao
**/

package npap.cater.unr.edu.client.managed.activity;

import npap.cater.unr.edu.client.managed.request.ApplicationEntityTypesProcessor;
import npap.cater.unr.edu.client.managed.request.ApplicationRequestFactory;
import npap.cater.unr.edu.client.managed.ui.ContactListView;
import npap.cater.unr.edu.client.managed.ui.ContactMobileListView;
import npap.cater.unr.edu.client.managed.ui.FileListView;
import npap.cater.unr.edu.client.managed.ui.FileMobileListView;
import npap.cater.unr.edu.client.managed.ui.ProjectListView;
import npap.cater.unr.edu.client.managed.ui.ProjectMobileListView;
import npap.cater.unr.edu.client.proxy.ContactProxy;
import npap.cater.unr.edu.client.proxy.FileProxy;
import npap.cater.unr.edu.client.proxy.ProjectProxy;
import npap.cater.unr.edu.client.scaffold.ScaffoldApp;
import npap.cater.unr.edu.client.scaffold.place.ProxyListPlace;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.inject.Inject;

public class ApplicationRooMasterActivities implements ActivityMapper{

	/**
	 * @uml.property  name="requests"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	protected ApplicationRequestFactory requests;

    /**
	 * @uml.property  name="placeController"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    protected PlaceController placeController;
    
    @Inject
    public ApplicationRooMasterActivities(ApplicationRequestFactory requests, PlaceController placeController) {
        this.requests = requests;
        this.placeController = placeController;
    }

    public Activity getActivity(Place place) {
        if (!(place instanceof ProxyListPlace)) {
            return null;
        }
        ProxyListPlace listPlace = (ProxyListPlace) place;
        return new ApplicationEntityTypesProcessor<Activity>() {

            @Override
            public void handleContact(ContactProxy isNull) {
                setResult(new ContactListActivity(requests, ScaffoldApp.isMobile() ? ContactMobileListView.instance() : ContactListView.instance(), placeController));
            }

            @Override
            public void handleProject(ProjectProxy isNull) {
                setResult(new ProjectListActivity(requests, ScaffoldApp.isMobile() ? ProjectMobileListView.instance() : ProjectListView.instance(), placeController));
            }

			@Override
			public void handleFile(FileProxy proxy) {
				// TODO Auto-generated method stub
				setResult(new FileListActivity(requests, ScaffoldApp.isMobile() ? FileMobileListView.instance() : FileListView.instance(), placeController));
			}
        }.process(listPlace.getProxyClass());
    }

}
